package com.ymatou.iapi.productquery.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONObject;

import com.ymatou.iapi.productquery.compare.ProductQueryInterface;
import com.ymttest.business.YmatouAutoTestCall;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;

public class GetProductBriefByProductIdCall extends YmatouAutoTestCall implements ProductQueryInterface{
	private static String opurl="api/Product/GetProductBriefByProductId";
	
	public GetProductBriefByProductIdCall(){
		super(EnvSetup.getSystemUrl("productquery"), opurl, "GET", "PARAM");
	}
	
	
	@Override
	public void addDefHeader(){
		//client.addHeader("Content-Type", "application/json");
	}
	@Override
	public void callService() throws ClientProtocolException, IOException{
		super.callService();
		if(getJsonObject().get("Data").isJsonNull()){
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			super.callService();
		}
	}
	public JSONObject callAndGetReturnData(String productId){
		return callAndGetReturnData(MapUtil.hashMap("ProductId",productId));
	}
	
	
	public JSONObject callAndGetReturnData(String productId,boolean isTradeIsolation){
		return callAndGetReturnData(MapUtil.hashMap("ProductId",productId,"IsTradeIsolation",isTradeIsolation));
	}
	
	 
	@Override
	public JSONObject search(List<String> productList) {
		return this.callAndGetReturnData( productList.get(0));
	}
	
	

	
	public static void main(String[] args) {
		List<String> aList = new ArrayList<>();
		aList.add("3f31b27c-b810-423d-8057-ed22870db19c");
		//aList.add("5eb52acf-1d0c-4d60-99ee-49d4d55e1bf8");
		new GetProductBriefByProductIdCall().search(aList);
	}
}
